Add file-based crash/diagnostics logging with in-app export - #7
Merged
Conversation
Capture unhandled exceptions to a rotating log file on device so the user can export it and hand it back for diagnosis (added to chase the runtime "An unhandled error has occurred" → black-reload crash after backgrounding). - FileLogStore: thread-safe, append-only sink under AppDataDirectory/logs with 512 KB size-based rotation (current + one backup); never throws. - FileLoggerProvider: routes ILogger output (incl. Blazor's own Error-level log for an unhandled component exception) into the store at Information+. - Global hooks write to the same store: AndroidEnvironment.UnhandledException- Raiser (the reliable .NET-Android catch-all, wired in MainActivity), AppDomain.UnhandledException, and TaskScheduler.UnobservedTaskException. - ILogExporter (Core) abstracts share/export: MauiLogExporter shares the file via the OS share sheet; NoopLogExporter (Web) hides the affordance. - SettingsView gains a Diagnostics → "Export log" button (Android only). - UI tests register a NoopLogExporter so SettingsView renders resolve. Web + Android (Debug) build clean; UI bUnit suite 46/46. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHCRc5CJ6595iMzEgYYdQp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
After the app runs a while in the background it shows "An unhandled error has occurred" and reloads to a black screen. Rather than keep guessing at the cause, this adds persistent on-device logging that captures the real exception so it can be exported from the phone and handed back for diagnosis.
What
FileLogStore— thread-safe, append-only log underAppDataDirectory/logs/sharpclient.logwith 512 KB size-based rotation (current + one.1backup). Writes never throw.FileLoggerProvider— routesILoggeroutput into the store atInformation+. This captures Blazor's ownError-level log emitted for an unhandled component exception (the "unhandled error" case) before the error UI shows.AndroidEnvironment.UnhandledExceptionRaiser(the reliable .NET-Android catch-all for background/network-thread crashes) — wired inMainActivity, resolves the store via DI at crash time.AppDomain.CurrentDomain.UnhandledExceptionTaskScheduler.UnobservedTaskExceptionILogExporter(Core abstraction):MauiLogExportershares the file via the OS share sheet;NoopLogExporter(Web) reportsIsAvailable == false.How to use
On the phone: reproduce the crash, then open Settings → Diagnostics → Export log and share the file (e.g. to chat/email). The log includes the timestamped stack trace.
Testing
NoopLogExportersoSettingsViewrenders resolve).🤖 Generated with Claude Code